package com.car.service;

import com.car.dao.CarDao;
import com.car.dao.EmployeeDao;
import com.car.dao.impl.CarDaoImpl;
import com.car.dao.impl.EmployeeDaoImpl;
import com.car.doamin.Car;
import com.car.doamin.Employee;
import com.car.utils.NumberUtils;

import java.util.Scanner;

public class EmployeeService {
    private static final EmployeeDao employeeDao = new EmployeeDaoImpl();
    private static final CarDao carDao = new CarDaoImpl();
    /**
     * 登录
     * @param scanner
     * @return
     */
    public Employee login(Scanner scanner) throws Exception {
        System.out.printf("员工登录");
        System.out.printf("请输入工号");
        String workId = scanner.next();
        System.out.printf("请输入密码");
        String password = scanner.next();
       Employee employee = employeeDao.findByWorkId(workId);
       if (employee == null || !"000000".equals(password)){
           return null;
       }
       return employee;
    }

    public void addCar(Employee employee, Scanner scanner) throws Exception {
        System.out.printf("上架汽车");
        Car car = new Car();
        System.out.printf("请输入汽车名字");
        String name = scanner.next();
        car.setName(name);
        System.out.printf("请输入汽车品牌");
        String brand = scanner.next();
        car.setBrand(brand);
        System.out.printf("请输入汽车颜色");
        String color = scanner.next();
        car.setColor(color);
        System.out.printf("请输入汽车类型");
        String type = scanner.next();
        car.setType(type);
        System.out.printf("请输入汽车价格");
        Double price = scanner.nextDouble();
        car.setPrice(price);
        car.setCarNum(NumberUtils.generateCardNum());
        car.setEmployeeId(employee.getId());
        // 新增到数据库
       int i =  carDao.add(car);
       if (i>0){
           System.out.printf("上架成功");
       }else {
           System.out.printf("操作失败");
       }
    }
}
